package com.farm.portal.service.impl;

import com.farm.portal.domain.Component;
import com.farm.core.auth.domain.LoginUser;
import com.farm.core.time.TimeTool;
import com.farm.portal.dao.ComponentDaoInter;
import com.farm.portal.service.ComponentServiceInter;
import com.farm.core.sql.query.DataQuery;

/* *
 *功能：组件库服务层实现类
 *详细：
 *
 *版本：v0.1
 *作者：FarmCode代码工程
 *日期：20141119144919
 *说明：
 */
public class ComponentServiceImpl implements ComponentServiceInter {
	private ComponentDaoInter componentDao;
//	private static final Logger log = Logger
//			.getLogger(ComponentServiceImpl.class);

	@Override
	public Component insertComponentEntity(Component entity, LoginUser user) {
		entity.setCuser(user.getId());
		entity.setCtime(TimeTool.getTimeDate14());
		entity.setCusername(user.getName());
		entity.setEuser(user.getId());
		entity.setEusername(user.getName());
		entity.setEtime(TimeTool.getTimeDate14());
		return componentDao.insertEntity(entity);
	}

	@Override
	public Component editComponentEntity(Component entity, LoginUser user) {
		Component entity2 = componentDao.getEntity(entity.getId());
		entity2.setEuser(user.getId());
		entity2.setEusername(user.getName());
		entity2.setEtime(TimeTool.getTimeDate14());
		entity2.setContext(entity.getContext());
		entity2.setIconclass(entity.getIconclass());
		entity2.setTitle(entity.getTitle());
		entity2.setPcontent(entity.getPcontent());
		entity2.setPstate(entity.getPstate());
		entity2.setUrl(entity.getUrl());
		componentDao.editEntity(entity2);
		return entity2;
	}

	@Override
	public void deleteComponentEntity(String id, LoginUser user) {
		// TODO 自动生成代码,修改后请去除本注释
		componentDao.deleteEntity(componentDao.getEntity(id));
	}

	@Override
	public Component getComponentEntity(String id) {
		// TODO 自动生成代码,修改后请去除本注释
		if (id == null) {
			return null;
		}
		return componentDao.getEntity(id);
	}

	@Override
	public DataQuery createComponentSimpleQuery(DataQuery query) {
		// TODO 自动生成代码,修改后请去除本注释
		DataQuery dbQuery = DataQuery
				.init(
						query,
						"FARM_PORTAL_COMPONENT",
						"ID,VIEWIMGID,CONTEXT,URL,ICONCLASS,PCONTENT,TITLE,PSTATE,EUSER,EUSERNAME,CUSERNAME,CUSER,CTIME,ETIME");
		return dbQuery;
	}

	// ----------------------------------------------------------------------------------
	public ComponentDaoInter getComponentDao() {
		return componentDao;
	}

	public void setComponentDao(ComponentDaoInter dao) {
		this.componentDao = dao;
	}

}
